<?php
if ( !isGod() )
	if ( !getRights($mod,'full') )
	{
		showMsg('Không có quyền truy cập vào trang này !','error','center');
		die();
	}
//xoa cac module kg su dung
$rs = $link->execute("SELECT * FROM um_module");
while(!$rs->EOF)
{
	if ( !file_exists($info['module_path'] . $rs->fields('modname') ) )	//kg co module trong thu muc module
		$link->execute("DELETE FROM um_module WHERE modname='" . $rs->fields('modname') . "'");
		
	$rs->movenext();
}

//lay group_id	
$gid = (!get_magic_quotes_gpc()) ? addslashes(@$_GET['gid']) : @$_GET['gid'];

$sql = "SELECT * FROM um_group WHERE gid=$gid";
$rs_g = $link->execute($sql);
	
//lay danh sach cac modules
$sql = "SELECT * FROM um_module";
$rs_m = $link->execute($sql);

?>
<?php
	echo '<form name="frmGAccess" action="admin.php?mod=UManager&act=process_gaccess" method="POST">';
	echo '<table cellpadding="0" cellspacing="1" border="0" width="98%" align="center" class="clsMyBorder">';

	echo '<tr>';
	echo '<td height="23" bgcolor="#6699CC" colspan="7" class="clsTitle">&nbsp;Phân quyền cho nhóm: <font color="#FFFF00">' . $rs_g->fields('gname') . '</font></td>';
	echo '</tr>';
	
	echo '<tr>';
	echo '<td height="22" bgcolor="#AAAAAA" align="center" class="clsBold">Tên module</td>';
	echo '<td bgcolor="#AAAAAA" align="center" class="clsBold">Mô tả module</td>';		
	echo '<td bgcolor="#AAAAAA" align="center" class="clsBold">Xem</td>';				
	echo '<td bgcolor="#AAAAAA" align="center" class="clsBold">Thêm dữ liệu</td>';		
	echo '<td bgcolor="#AAAAAA" align="center" class="clsBold">Hiệu chỉnh</td>';				
	echo '<td bgcolor="#AAAAAA" align="center" class="clsBold">Xóa</td>';				
	echo '</tr>';
	
	$stt = 0;
	while ( !$rs_m->EOF )
	{
		if ( $stt % 2 == 0 )	$clr = '#FFFFCC';
		else	$clr = '#F0F0F0';


		$sql = "SELECT * FROM gaccess WHERE gid=" . $gid . " AND modname='" . $rs_m->fields('modname') . "'";

		$rs_info = $link->execute($sql);

		echo '<tr>';
		echo '<td bgcolor="' . $clr . '">&nbsp;' . $rs_m->fields('modname') . '</td>';
		echo '<td bgcolor="' . $clr . '">&nbsp;' . $rs_m->fields('moddesc') . '</td>';		
		echo '<td  bgcolor="' . $clr . '" align="center">';
			if ( $rs_info->fields('view') == 1 )	echo '<input type="checkbox" name="chk' . $stt . '_0" value="view_' . $rs_m->fields('modname') . '" checked>';
			else echo '<input type="checkbox" name="chk' . $stt . '_0" value="view_' . $rs_m->fields('modname') . '">';
		echo '</td>';				
		echo '<td  bgcolor="' . $clr . '" align="center">';
			if ( $rs_info->fields('add') == 1 )	echo '<input type="checkbox" name="chk' . $stt . '_1" value="add_' . $rs_m->fields('modname') . '" checked>';
			else echo '<input type="checkbox" name="chk' . $stt . '_1" value="add_' . $rs_m->fields('modname') . '">';
		echo '</td>';		
		echo '<td  bgcolor="' . $clr . '" align="center">';
			if ( $rs_info->fields('edit') == 1 )	echo '<input type="checkbox" name="chk' . $stt . '_2" value="edit_' . $rs_m->fields('modname') . '" checked>';
			else echo '<input type="checkbox" name="chk' . $stt . '_2" value="edit_' . $rs_m->fields('modname') . '">';
		echo '</td>';				
		echo '<td  bgcolor="' . $clr . '" align="center">';
			if ( $rs_info->fields('delete') == 1 )	echo '<input type="checkbox" name="chk' . $stt . '_3" value="delete_' . $rs_m->fields('modname') . '" checked>';
			else echo '<input type="checkbox" name="chk' . $stt . '_3" value="delete_' . $rs_m->fields('modname') . '">';
		echo '</td>';
		echo '</tr>';
		echo '<input type="hidden" name="hid' . $stt . '" value="' . $rs_info->fields('modname') . '">';
		
		$stt++;
		$rs_info->close();
		$rs_m->movenext();
	}
	
	echo '<tr>';
	echo '<td colspan="7" bgcolor="#000066" align="right" class="clsPanelButton">';
	echo '<input type="submit" name="cmdOK" value="Phân quyền &raquo">&nbsp;&nbsp;';
	echo '</td>';
	echo '</tr>';
	echo '</table>';
	echo '<input type="hidden" name="gid" value="' . $gid . '">';
	echo '<input type="hidden" name="totalModule" value="' . $stt . '">'
?>

